#include "stdafx.h"
#include "XNativeHost.h"
#include "XWebView.h"
#include "RankListWnd.h"

XNativeHost::XNativeHost() {
}

XNativeHost::~XNativeHost() {
}

HWND XNativeHost::OnRealWndCreate(SOUI::SRealWnd *pRealWnd) {
    const SOUI::SRealWndParam &param = pRealWnd->GetRealWndParam();
    
    SOUI::SHostWnd *pWnd = nullptr;
    if (param.m_strClassName == _T("XWebView")) {
        pWnd = new XWebView();
    } else if (param.m_strClassName == _T("XRankListWnd")) {
        pWnd = new XRankListWnd();
    }
    
    if (pWnd != nullptr) {
        pWnd->Create(pRealWnd->GetContainer()->GetHostHwnd(), WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 0, 0, 0);
        pWnd->SetName(param.m_strWindowName);
        pRealWnd->SetData(pWnd);
        return pWnd->m_hWnd;
    }
    return nullptr;
}

void XNativeHost::OnRealWndDestroy(SOUI::SRealWnd *pRealWnd) {
    const SOUI::SRealWndParam &param = pRealWnd->GetRealWndParam();
    
    SOUI::SHostWnd *pWnd = (SOUI::SHostWnd *)pRealWnd->GetData();
    if (pWnd) {
        pWnd->DestroyWindow();
        delete pWnd;
    }
}
BOOL XNativeHost::OnRealWndInit(SOUI::SRealWnd *pRealWnd) {
    const SOUI::SRealWndParam &param = pRealWnd->GetRealWndParam();
    {
        SOUI::SHostWnd *pWnd = (SOUI::SHostWnd *)pRealWnd->GetData();
        if (pWnd) {
            pWnd->SendMessage(WM_INITDIALOG);
        }
    }
    
    return FALSE;
}

